//
//  SEHospitalAPI.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/19.
//

import Moya

enum SEHospitalAPI {
    /// type 是否可以做检查 - 1: 是, 0: 否, 如果是检查检验的医院传1, 预约挂号不传
    case hospitalList(pageNum: Int,
                             pageSize: Int = 10,
                             code: String,
                             province: String,
                             city: String,
                             region: String,
                             hospitalName: String,
                             distance: String,
                             level: String,
                             lon: String,
                             lat: String,
                             type: String,
                             deviceId: String)
    case hospitalDetail(id: String)
}

extension SEHospitalAPI: TargetType {
    var baseURL: URL {
        return URL(string: SEApiManager.baseUrl)!
    }

    var path: String {
        switch self {
        case .hospitalList: return "/smarteye/smarteye-register/source/general/queryHospital"
        case .hospitalDetail: return "/smarteye/smarteye-base/doctor/query/recommend"
        }
    }

    var method: Moya.Method {
        return .post
    }

    var sampleData: Data {
        return "".data(using: .utf8)!
    }

    var task: Task {
        return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return SEApiManager.headers
    }

    private var parameters: [String: Any] {
        switch self {
        case let .hospitalList(pageNum, pageSize, code, province, city, region, hospitalName, distance, level, lon, lat, type, deviceId):
            return ["pageNum": pageNum,
                    "pageSize": pageSize,
                    "code": code,
                    "province": province,
                    "city": city,
                    "region": region,
                    "hospitalName": hospitalName,
                    "distance": distance,
                    "level": level,
                    "lon": lon,
                    "lat": lat,
                    "type": type,
                    "deviceId": deviceId
            ]
        case .hospitalDetail(let id):
            return ["id": id]
        }
    }
}
